const Angular = require('angular');
const app = Angular.module('selfTableApp', []);
import selfTable from '../../directives/selftTable';
import csfTable from '../../components/csfTable';
import './index.scss'
csfTable(app);
selfTable(app);
app.controller('selfTableCtr', ['$scope', '$compile', '$http', function ($scope, $compile, $http) {
    $scope.aggs = ['deviceid_linkid', 'event_name', 'dst_ip', 'alarm_category'];
    $http.get('/getForceData').then(res => {
        $scope.sourceData = res.data.data.aggs;
        console.log($scope.sourceData);
    })
    $scope.$on('getTableData', (e, data) => {
        console.log(e, data)
    })
    $scope.mainCtr = {
        test: 'compile',
        tableHead: [{
            showCheckbox: true,
        }, {
            name: '姓名',
            key: 'name',
            sort: true
        }, {
            name: '班级',
            key: 'classes',
            formatter(item) {
                let map = {
                    12: '一年级2班',
                    11: '一年级1班'
                }
                return map[item.classes];
            }
        }, {
            name: '操作',
            key: 'operate',
            width: '200px',
            showRender: false,
            render() {
                return `<button class="ui button primary" ng-click="mainCtr.operate.hello()">hello</button>
                    <button class="ui button primary" ng-click="mainCtr.operate.world()">world</button>  
                    `
            },
            operate: {
                hello: () => {
                    $scope.mainCtr.hello();
                },
                world: (e, item) => {
                    $scope.mainCtr.world();
                }
            },
        }],
        tableData: [{
                name: 'test2',
                classes: '12',
            },
            {
                name: 'test1',
                classes: '11',
            }
        ],
        tableData2: [{
                name: 'test2',
                classes: '12',
            },
            {
                name: 'test1',
                classes: '11',
            }
        ],
        hello() {
            console.log('hello world');
        },
        world() {
            console.log(this.tableData, this.tableData2);
        }
    }
    $scope.$on('$destroy', function () {
        console.log('selfTable destroyed');
    });
}])